package cz.proks.easyhelpdesk.gae.api.impl.dbo;

import org.springframework.beans.BeanUtils;

import cz.proks.easyhelpdesk.gae.api.impl.dbo.base.ConvertibleDbo;
import cz.proks.easyhelpdesk.gae.api.impl.dbo.base.IdentifiableHelpdeskModelDbo;



public class Filter extends cz.proks.easyhelpdesk.api.model.Filter implements IdentifiableHelpdeskModelDbo, ConvertibleDbo<cz.proks.easyhelpdesk.api.model.Filter> {    
    private Helpdesk helpdesk;
    private User user;                   
    
    @Override
    public Long getUserId() {
        return super.getUserId();
    }

    @Override
    public void setUserId(Long userId) {
        super.setUserId(userId);
        
        if (userId != null && user == null) {
            user = new User();
            user.setId(userId);
        } else if (userId != null)
            user.setId(userId);
        else
            user = null;
    }    

    @Override
    public Long getHelpdeskId() {    
        return super.getHelpdeskId();
    }
    
    @Override
    public void setHelpdeskId(Long helpdeskId) {
        super.setHelpdeskId(helpdeskId);
        
        if (helpdeskId == null)
            helpdesk = null;            
        else {
            helpdesk = new Helpdesk();        
            helpdesk.setId(helpdeskId);
        }
    }

    @Override
    public Helpdesk getHelpdesk() {
        return helpdesk;
    }

    @Override
    public void setHelpdesk(Helpdesk helpdesk) {
        this.helpdesk = helpdesk;
        setHelpdeskId(helpdesk != null ? helpdesk.getId() : null);
    }        
    
    public User getUser() {
        return user;
    }

    public void setUser(User user) {
        this.user = user;
        super.setUserId(user != null ? user.getId() : null);
    }

    public void toDbo(cz.proks.easyhelpdesk.api.model.Filter filter) {
        BeanUtils.copyProperties(filter, this);
    }
    
    public cz.proks.easyhelpdesk.api.model.Filter asDomain() {
        cz.proks.easyhelpdesk.api.model.Filter filter = new cz.proks.easyhelpdesk.api.model.Filter();
        BeanUtils.copyProperties(this, filter, new String[] {"helpdesk"});        
        return filter;
    }

}
